package p270jp.pxv.android.view;

import android.content.Context;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import androidx.databinding.DataBindingUtil;
import com.google.android.material.textview.MaterialTextView;
import p014ae.View$OnClickListenerC0158t;
import p045be.View$OnClickListenerC1058b0;
import p090d0.C2518n;
import p134ei.PixivAnalytics;
import p270jp.pxv.android.R;
import p270jp.pxv.android.legacy.model.PixivNovel;
import p270jp.pxv.android.legacy.model.PixivSeries;
import p314lg.ViewNovelOutlineBinding;
import p325m0.MutabilityOwnership;
import p470ri.HashtagService;
import p677zi.PixivImageLoader;

/* renamed from: jp.pxv.android.view.NovelOutlineView */
/* loaded from: classes2.dex */
public class NovelOutlineView extends RelativeLayout {

    /* renamed from: c */
    public PixivNovel f19598c;

    /* renamed from: e */
    public final int f19600e;

    /* renamed from: a */
    public final HashtagService f19596a = (HashtagService) C2518n.m7641d(HashtagService.class);

    /* renamed from: b */
    public ViewNovelOutlineBinding f19597b = (ViewNovelOutlineBinding) DataBindingUtil.m11370c(LayoutInflater.from(getContext()), R.layout.view_novel_outline, this, true);

    /* renamed from: d */
    public PixivAnalytics f19599d = (PixivAnalytics) C2518n.m7641d(PixivAnalytics.class);

    /* renamed from: f */
    public PixivImageLoader f19601f = (PixivImageLoader) C2518n.m7641d(PixivImageLoader.class);

    public NovelOutlineView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet, 0);
        this.f19597b.f21949s.getViewTreeObserver().addOnGlobalLayoutListener(new p374nm.NovelOutlineView(this));
        this.f19597b.f21948r.setOnClickListener(new View$OnClickListenerC0158t(this, 27));
        MutabilityOwnership.m3745m(context, "context");
        TypedValue typedValue = new TypedValue();
        if (context.getTheme().resolveAttribute(R.attr.colorCharcoalLink1, typedValue, true)) {
            this.f19600e = typedValue.data;
            return;
        }
        throw new IllegalStateException("Charcoal Theme, もしくは Charcoal Bridge Theme を利用してください");
    }

    /* renamed from: a */
    public final void m4480a() {
        if (!(this.f19598c == null || this.f19597b.f21949s.getMeasuredWidth() == 0)) {
            this.f19597b.f21949s.removeAllViews();
            this.f19597b.f21949s.setShowDividers(2);
            int dimensionPixelSize = getResources().getDimensionPixelSize(R.dimen.novel_tag_padding);
            LinearLayout linearLayout = null;
            boolean z = true;
            int i = 0;
            for (int i2 = 0; i2 < this.f19598c.tags.size(); i2++) {
                String str = this.f19598c.tags.get(i2).name;
                MaterialTextView materialTextView = new MaterialTextView(getContext(), null);
                materialTextView.setPadding(dimensionPixelSize, 0, dimensionPixelSize, 0);
                materialTextView.setText(this.f19596a.m2580a(str));
                materialTextView.setTextColor(this.f19600e);
                materialTextView.setOnClickListener(new View$OnClickListenerC1058b0(this, str, 5));
                materialTextView.measure(0, 0);
                int measuredWidth = materialTextView.getMeasuredWidth();
                i += measuredWidth;
                if (linearLayout != null && i > this.f19597b.f21949s.getMeasuredWidth()) {
                    this.f19597b.f21949s.addView(linearLayout);
                    z = true;
                    i = measuredWidth;
                }
                if (z) {
                    linearLayout = new LinearLayout(getContext());
                    linearLayout.setId(i2 + 1);
                    linearLayout.setPadding(0, dimensionPixelSize, 0, dimensionPixelSize);
                    linearLayout.setOrientation(0);
                    linearLayout.setShowDividers(2);
                    linearLayout.setGravity(1);
                    z = false;
                }
                linearLayout.addView(materialTextView);
            }
            if (linearLayout != null) {
                this.f19597b.f21949s.addView(linearLayout);
            }
        }
    }

    public void setNovel(PixivNovel pixivNovel) {
        this.f19598c = pixivNovel;
        this.f19601f.m59g(getContext(), pixivNovel.imageUrls.getMedium(), this.f19597b.f21947q);
        this.f19597b.f21951u.setText(pixivNovel.title);
        this.f19597b.f21950t.setText(getContext().getResources().getString(R.string.novel_words_format, Integer.valueOf(pixivNovel.textLength)));
        PixivSeries pixivSeries = pixivNovel.series;
        if (pixivSeries == null || pixivSeries.f19077id <= 0) {
            this.f19597b.f21948r.setVisibility(8);
        } else {
            this.f19597b.f21948r.setVisibility(0);
            this.f19597b.f21948r.setText(pixivNovel.series.title);
        }
        if (pixivNovel.tags.size() > 0) {
            m4480a();
        } else {
            this.f19597b.f21949s.setVisibility(8);
        }
    }
}
